import java.util.Random;

public class Stresser {

	private Sentence_itf so;
	private Random rand = new Random();

	public static void main(String[] args) {
		Client.init();

		Sentence_itf s = (Sentence_itf)Client.lookup("Stresseur");
		if(s == null) {
			s = (Sentence_itf)Client.create(new Sentence());
			Client.register("Stresseur", s);
		}
		new Stresser(s);
	}

	public Stresser(Sentence_itf s) {
		this.so = s;
		/*
		so.lock_write();
		System.out.println("write.");
		so.unlock();//*/
		/*
		so.lock_read();
		System.out.println("read.");
		so.unlock();//*/
		/*
		so.lock_read();
		System.out.println("read.");
		so.unlock();//*/
		/*
		so.lock_write();
		System.out.println("write.");
		so.unlock();//*/
		//*
		for(int i = 0 ; i < 100 ; i++) {
			int choice = rand.nextInt(10);
			//System.out.print(choice + " Operation number " + (i+1) + " : ");
			if(choice < 9) {
				so.lock_read();
				//System.out.println("read.");
				so.unlock();
			} else {
				so.lock_write();
				//System.out.println("write.");
				so.unlock();
			}
		}//*/
		System.out.close();
		System.err.close();
	}

}
